<?php
error_reporting(0);
session_start();
header("Content-type: text/html; charset:utf-8");

//config
$domain="/";//域名 配ajajx
$siteurl="http://www.longui.com/";
$sitename='深圳信息职业技术学院';
$technicalemail = 'isrn@qq.com';
define("DEFAULT_CHARSET" , 'utf8');
$prefix="lm";//prefix
global $xajaxFuncs;
$xajaxFuncs=array();
global $prefix;
$servername = 'localhost';		//数据库所在目录
$dbusername = 'root';	//数据库用户名
$dbpassword = '';	//数据库密码
$dbname		= 'xxw';		//数据库名称
$tmpname='xxw/';//模版所在目录
define('ROOT_PATH','');//程序所在目录 UBB有关等
define('BIC_ROOT',substr(dirname(__FILE__),0,-8));	//网站目录
define('LOG_OPEN',true);	//网站日志
define('MULTI_CITY',false);	//多城市模块
$multi_city_mod=array();    //多城市模块[需要自动加载的模块]
define('USE_OFTEN_PRICE',false);	//开启时时房价功能
$OFTEN_PRICE_SORTID=array();	//时时房价入口表
define('CHECK_BOOKING',false);	//订单检查[在/sa/index.php里面配置 ]

include BIC_ROOT.'config.inc.php';

/**
 * **********************
 * 配置smarty目录
 * 已更新 ,不用管下面的代码
 */
$pathEnd=str_replace("\\",'/',substr($_SERVER['DOCUMENT_ROOT'],-1));
if($pathEnd!='/') $smartydir='/';
define('TMPE_PATH',$smartydir);

/*设置时区*/
if(function_exists('date_default_timezone_set')) {
    @date_default_timezone_set("Asia/Shanghai");
}

//datebase
//echo ($_SERVER['DOCUMENT_ROOT']);
require_once ( BIC_ROOT."includes/class/db_mysql.php" );
$db = new clsMYSQL();
$db->Host=$servername;
$db->Database=$dbname;
$db->User=$dbusername;
$db->Password=$dbpassword;
$db->connect();
require_once (BIC_ROOT.'includes/class/appDB.class.php');
$app = new appDB();
$app->db = $dbname;
mysql_query("set names ".DEFAULT_CHARSET."");
//templates
//echo BIC_ROOT.'<br />';
//echo(dirname(__FILE__)."/xajaxResponse.inc.php");
//require_once (BIC_ROOT.'/includes/class/xajax/xajax.inc.php');
//升级为0.5 rc2
require_once (BIC_ROOT.'includes/class/xajax_0.5/xajax_core/xajax.inc.php');

require_once BIC_ROOT.'includes/class/smarty/Smarty.class.php';
class Smarty_DMsys extends Smarty {
    function Smarty_DMsys() {
        $this->Smarty();
        $this->template_dir =BIC_ROOT.'templates/';
        $this->compile_dir = BIC_ROOT.'temp/compiles/';
        $this->cache_dir = BIC_ROOT.'temp/cache/';
        $this->config_dir = BIC_ROOT.'temp/configs/';
        //echo $this->compile_dir;
        $this->left_delimiter='<{';
        $this->right_delimiter='}>';
        $this->caching = false;
        $this->debugging = false;
        $this->compile_check= true;
    }
}
$ttt = new Smarty_DMsys;
$ttt->assign('rootpath',BIC_ROOT);


require_once ( BIC_ROOT."includes/class/tviewpage.php" );
require_once (BIC_ROOT.'includes/class/class.Chinese.php');
require_once (BIC_ROOT.'includes/class/lm_page.class.php');
require_once (BIC_ROOT.'includes/class/splite_utf8.php');
require_once (BIC_ROOT."includes/function/function.php");
require_once (BIC_ROOT.'jimu/core.php');


//多语言系统
if(!isset($_SESSION[LG])) {
    $_SESSION[LG]='zh';//
}
if(!isset($_SESSION[XS])) {
    $_SESSION[XS]='zh';
    $_SESSION['LG']='zh';
}
if($_SESSION[XS]=='bg') {
    $_SESSION['LG']='zh';
}
$ttt->assign('LG',$_SESSION['LG']);
$ttt->assign('XS',$_SESSION['XS']);
require ( BIC_ROOT."lang/".$_SESSION['LG'].".php");
$ttt->assign('weblang',$weblang);


//定义时间常量
define('INT_SECOND', 1);
define('INT_MINUTE', 60);
define('INT_HOUR', 3600);
define('INT_DAY', 86400);
define('INT_WEEK', 604800);
define('INT_MONTH', 2592000);

Tr($_config,'_config');

switch($_SERVER['PHP_SELF']) {
    case Sf('/admin/',$_SERVER['PHP_SELF']): {
            addjs('ext');
            if ($_SESSION[logined]!=1) {
                Ts('admin/login.html');
                exit;
            }
            if($_SERVER['HTTP_REFERER']==''&&!Sf('index.php',$_SERVER['PHP_SELF'])) {
                if(($_GET['mid']==''||$_GET['from']!='b') && !Sf('treedata.php',$_SERVER['PHP_SELF'])) {
                    Ja('非正确入口！');
                    exit;
                }

            }
            if(1) {
                $rizhi=0;//日志打开与否

                //写入日记详细,为什么要提 上来?因为可以在下一步进行适当的修改
                $_log['user']=$_SESSION['userinfo']['user'];
                $_log['from']=$_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];


                switch($_SERVER['PHP_SELF']) {//配置 监测模块 或监测人
                    case  Sf('d.php',$_log['from']):
                    case  Sf('del',$_log['from']): {
                            $rizhi=1;

                            if($_REQUEST['did']!='') {
                                $_dcfg = Dga('dcfg',"id={$_REQUEST['did']}");
                                $_i = $_REQUEST['did'];
                            }else {
                                $_dcfg = Dga('infosort',"id={$_REQUEST['sortid']}");
                                $_i = $_REQUEST['sortid'];
                            }

                            $_log['info']="对ID为:[{$_i}]的模块[{$_dcfg['title']}],ID为[{$_REQUEST['id']}]的数据执行删除操作！";
                            $_log['operate']='删除';
                        }
                    case  Sf('u.php',$_log['from']):
                    case  Sf('infoupdate',$_log['from']): {
                            $rizhi=1;

                            if($_REQUEST['did']!='') {
                                $_dcfg = Dga('dcfg',"id={$_REQUEST['did']}");
                                $_i = $_REQUEST['did'];
                            }else {
                                $_dcfg = Dga('infosort',"id={$_REQUEST['sortid']}");
                                $_i = $_REQUEST['sortid'];
                            }

                            $_log['info']="对ID为:[{$_i}]的模块[{$_dcfg['title']}]，gid为[{$_REQUEST['zh']['gid']}]的数据执行修改操作！";
                            $_log['operate']='修改';
                        }

                }

                if($rizhi) {//根据需要写操作日志
                    $_log['addtime']=time();
                    $_log['date']=$_log['addtime'];
                    $_log['sortid']=20;
                    $_log['ip']=getip();
                    $_log['lg']='zh';
                    $_log['gid']=Mct();
                    Di('log',$_log);
                    $_log=array();	//注消此数组
                    unset($_log);
                }

            }
            if($_SESSION['userinfo']['rcfg']!='S') {//操作权限验证
                if(($_SERVER['HTTP_REFERER']!='')&&(!Sf('index.php',$_SERVER['HTTP_REFERER']))) {
                    $tzurl=$_SERVER['HTTP_REFERER'];
                }else {
                    $tzurl='/admin/error.htm';
                }
                if(($_GET['mid']!=''||$_GET['from']=='b')) {
                    !(Sf('F',$_SESSION['myright'][$_GET['mid']])||Sf('R',$_SESSION['myright'][$_GET['mid']]))&&Ja('没有最基本读权限',$tzurl);
                }
                if(!(Sf('index.php',$_SERVER['PHP_SELF'])||Sf('treedata.php',$_SERVER['PHP_SELF'])||Sf('c.php',$_SERVER['PHP_SELF'])||Sf('l.php',$_SERVER['PHP_SELF'])||Sf('treedata.php',$_SERVER['PHP_SELF']))) {
                    //Ja($_SERVER['PHP_SELF']);
                    myright();
                }//Jc($_SESSION[myright]);
                if( Sf('/d.php',$_SERVER['PHP_SELF'])||Sf('del',$_SERVER['QUERY_STRING'])) {//删除权限
                    if(!(Sf('F',$_SESSION['myright'][$_GET['mid']])||Sf('D',$_SESSION['myright'][$_GET['mid']]))) {
                        Ja('没有删除权限',$tzurl);
                        exit;
                    }
                }

                if( Sf('/c.php',$_SERVER['PHP_SELF'])||Sf('add',$_SERVER['QUERY_STRING'])) {//删除权限
                    if(!(Sf('F',$_SESSION['myright'][$_GET['mid']])||Sf('D',$_SESSION['myright'][$_GET['mid']]))) {
                        Ja('没有添加权限',$tzurl);
                        exit;
                    }
                }

                if( Sf('u.php',$_SERVER['PHP_SELF'])||Sf('/t.php',$_SERVER['PHP_SELF'])||Sf('edit',$_SERVER['QUERY_STRING'])||Sf('mod',$_SERVER['QUERY_STRING'])||Sf('modify',$_SERVER['QUERY_STRING'])||Sf('zhen',$_SERVER['QUERY_STRING'])||Sf('jia',$_SERVER['QUERY_STRING'])) {//更新权限
                    //Jc($_SESSION[myright]);
                    if(!(Sf('F',$_SESSION['myright'][$_REQUEST['mid']])||Sf('U',$_SESSION['myright'][$_REQUEST['mid']]))) {
                        Ja('没有更新权限',$tzurl);
                        exit;
                    }
                }

            }
            break;
        }

}
//定义网站关键字与header.htm相关
function regkeys($var) {
    global $lang;
    static $temp='';
    if($temp=='') {
        $temp=Dga('base',"del!=1 {$lang} limit 1");
    }
    return $temp[$var];
}

/*banner img en*/
if($_SESSION['LG']=='en') {
    Tr('en','en');
}

/*
 * 城市 判断
*/
global $city;
global $city_data;
function get_the_city($fields='') {
    global $city;
    global $city_data;
    if(''==$city_data) {
        $name = get_url_name();
        $city_data = Dga('city',"name='{$name}'");
        if(''==$city_data) {
            $city_data = Dga('city',"name='www'");
        }
        //$city = " and city={$city_data['id']} ";
    }
    if($fields!='')    return $city_data[$fields];
}
function get_url_name() {
    $url = explode('.',$_SERVER['HTTP_HOST']);
    $url_num = count($url);
    if(2==$url_num) {
        $name = 'www';
    }else {
        $name = $url[0];
    }
    return $name;
}
function the_city_id() {
    return get_the_city('id');
}

/**
 *根据城市id获取城市信息
 * @param int $id 城市id
 * @param string|bool $fields 返回数据字段|默认为false[返回城市全部数据]
 */
function the_city($id,$fields=false) {
    $city_data = Dga('city',"id={$id}");
    if($fields!==false) {
        return $city_data[$fields];
    }
    return $city_data;
}

/**
 *获取后台用户城市
 * @param string $user_id   用户id *留空为当前后台登陆用户id
 * @param string $field 返回特定字段的数据
 * @return string
 */
function get_user_city($user_id,$field='department') {
    if('' == $user_id) {
        $user_id = $_SESSION['userinfo']['id'];
    }
    $user=Dga('user',"id={$user_id}");
    return $user[$field];
}
if (MULTI_CITY){
    get_the_city();
}


